package com.heima.admin.job;

import com.heima.admin.services.WemediaNewsAutoScanService;
import com.heima.feigns.WemediaFeign;
import com.heima.model.common.dtos.ResponseResult;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import io.seata.common.util.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class WeMediaNewsAutoScanJob {
@Autowired
    WemediaFeign wemediaFeign;
@Autowired
WemediaNewsAutoScanService wemediaNewsAutoScanService;
@XxlJob("wemediaAutoScanJob")
    public ReturnT weMediaNewsAutoScanJob(String params){
    log.info("定时发布任务被触发  Start===========>");
    ResponseResult<List<Integer>> releaseResult = wemediaFeign.findRelease();
    if (releaseResult.getCode().intValue()!=0) {
        log.error("远程调用    wemedia服务异常，  原因：{}",releaseResult.getErrorMessage());
        return ReturnT.FAIL;
    }
    List<Integer> newsIdList = releaseResult.getData();
    if (CollectionUtils.isNotEmpty(newsIdList)) {
        for (Integer newsId : newsIdList) {
        wemediaNewsAutoScanService.autoScanByMediaNewsId(newsId);
        }
    }

    log.info("定时发布任务被触发  end===========>");



        return ReturnT.SUCCESS;
    }

}
